package jmc.util;



import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;





public class FileUtil {
	
	private static String basePath = "/temp/";
	
	public static String parseExtension(String fileName) {
		
		if (fileName != null) {
			for (int i = 0; i < fileName.length(); i++) {
				char aux = fileName.charAt(i);
				if (aux == '.') 
					return fileName.substring(i + 1);				
			}
		}
		return fileName;
	}
	
	public static Boolean isImage(String completeName) {
		String img = "image";
		return completeName.contains(img);		
	}

	

	public static File createTempFile(String data, String nombre){
		File outFile = new File(nombre);
		FileWriter out;

		try {
			out = new FileWriter(outFile);
			out.write(data);
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return outFile;		
	}
	
	public static String getWebappsPath(){
        String sep = System.getProperty("file.separator");
        return System.getProperty("catalina.base") + sep + "webapps";
    }
	/**
	 * Guarda el arhivo en el directorio temporal
	 * @param archivo
	 * 
	 */
	public static File writeFile(byte[] archivo, String nombre) throws Exception{		
		
		File file = new File(nombre);
				 
		FileOutputStream f =  new FileOutputStream(file);
	
		try {
			f.write(archivo);
			f.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return file;
	}

}
